<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>

<meta charset=utf-8>
<title>Insert title here</title>
<style type="text/css">
.err {
	font-size: 12px;
	color: #f00;
}
</style>
<link href="static/css/regist.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div id="outer">
		<div id="lay1">
			<div id="lay2">
				<div class="info">
					<div class="t1">会员注册</div>
					<div class="t2">小米商城</div>
				</div>
				<hr />
				<form action="user" method="post" onsubmit="return ff();">
					<input type="hidden" name="action" value="regist">
					<table align="center">
						<tr>
							<td>用户名：</td>
							<td><input placeholder="用户名" align="center" type="text"
								id="username" /><span class="err"></span></td>
						</tr>
						<tr>
							<td>密码：</td>
							<td><input placeholder="密码" align="center" type="text" /><span
								class="err"></span></td>
						</tr>
						<tr>
							<td>确认密码：</td>
							<td><input placeholder="确认密码" align="center"
								type="text" /><span class="err"></span></td>
						</tr>
						<tr>
							<td>邮箱：</td>
							<td><input placeholder="邮箱" align="center" type="email" /><span
								class="err"></span></td>
						</tr>
						<tr>
							<td>性别：</td>
							<td><input type="radio" name="sexy" />女 <input type="radio"
								name="sexy" />男 <span class="err"></span></td>
						</tr>
						<tr>
							<td><input type="submit" name="注册">
								</td>
							<td><input type="reset" name="重置"></td>
						</tr>
					</table>
				</form>
				<script type="text/javascript">
					function ff() {
						//var uname=document.getElementById("username");//通过ID获得元素
						var ips = document.getElementsByTagName("input");//获得一个数组来存放所有input标签
						var err = document.getElementsByClassName("err");
						//var name=uname.value;//取出用户输入的信息
						var reg = /^[a-zA-Z0-9]{6,20}$/;//定义正则式，用户名由数字或字母组成，长度6-20
						if (!reg.test(ips[1].value)) {//使用正则表达式验证用户输入信息
							err[0].innerHTML = "用户名是6-20数字或字母";//给用户名后的err动态填写错误原因
							return false;
						}else{
							err[0].innerHTML="";//输入格式正确后清空
						}
						reg=/^[0-9]{6}$/;//密码为六位数字
						if(!reg.test(ips[2].value)){
							err[1].innerHTML="密码必须为6位数字";
							return false;
						}else{
							err[1].innerHTML="";
						}
						if(ips[3].value!=ips[2].value){
							err[2].innerHTML="两次密码必须一致";
							return false;
						}else{
							err[2].innerHTML="";
						}
						reg = /^\w{3,}@[a-zA-Z0-9]{2,}\.[a-z]{2,}(\.cn)?$/; //邮箱验证
						if(!reg.test(ips[4].value)){
							err[3].innerHTML="邮箱格式不正确";
							return false;
						}else{
							err[3].innerHTML="";
						}
						if(!ips[5].checked&&(!ips[6].checked)){
							err[4].innerHTML="性别必选";
							return false;
						}else{
							err[4].innerHTML="";
						}
						return true;
					}
				</script>
			</div>
		</div>
	</div>
</body>
</html>